<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="是否阅读" prop="readFlag">
        <el-input v-model="queryParams.readFlag" placeholder="请输入是否阅读 0未阅读 1已经阅读" clearable size="small" @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['live:project-plan-event:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                   v-hasPermi="['live:project-plan-event:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="项目阶段id" align="center" prop="planId" />
      <el-table-column label="项目阶段事项内容" align="center" prop="planEventContent" />
      <el-table-column label="事项日期" align="center" prop="eventDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventDate) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否里程碑 0 不是 1是" align="center" prop="milestone" />
      <el-table-column label="是否延期 0 不是 1是" align="center" prop="postpone" />
      <el-table-column label="项目现场照片" align="center" prop="image" />
      <el-table-column label="是否需要协调 0不是 1是" align="center" prop="coordinate" />
      <el-table-column label="分管领导" align="center" prop="leaderId" />
      <el-table-column label="事项协调内容" align="center" prop="eventCoordinate" />
      <el-table-column label="事项结束 0不是 1是" align="center" prop="eventFlag" />
      <el-table-column label="是否审批 0未审批 1审批" align="center" prop="approval" />
      <el-table-column label="是否已经协调 0未协调 1已经协调" align="center" prop="coordination" />
      <el-table-column label="是否阅读 0未阅读 1已经阅读" align="center" prop="readFlag" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                     v-hasPermi="['live:project-plan-event:update']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                     v-hasPermi="['live:project-plan-event:delete']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目阶段id" prop="planId">
          <el-input v-model="form.planId" placeholder="请输入项目阶段id" />
        </el-form-item>
        <el-form-item label="项目阶段事项内容">
          <editor v-model="form.planEventContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="事项日期" prop="eventDate">
          <el-date-picker clearable size="small" v-model="form.eventDate" type="date" value-format="yyyy-MM-dd" placeholder="选择事项日期" />
        </el-form-item>
        <el-form-item label="是否里程碑 0 不是 1是" prop="milestone">
          <el-input v-model="form.milestone" placeholder="请输入是否里程碑 0 不是 1是" />
        </el-form-item>
        <el-form-item label="是否延期 0 不是 1是" prop="postpone">
          <el-input v-model="form.postpone" placeholder="请输入是否延期 0 不是 1是" />
        </el-form-item>
        <el-form-item label="是否需要协调 0不是 1是" prop="coordinate">
          <el-input v-model="form.coordinate" placeholder="请输入是否需要协调 0不是 1是" />
        </el-form-item>
        <el-form-item label="分管领导" prop="leaderId">
          <el-input v-model="form.leaderId" placeholder="请输入分管领导" />
        </el-form-item>
        <el-form-item label="事项协调内容" prop="eventCoordinate">
          <el-input v-model="form.eventCoordinate" placeholder="请输入事项协调内容" />
        </el-form-item>
        <el-form-item label="事项结束 0不是 1是" prop="eventFlag">
          <el-input v-model="form.eventFlag" placeholder="请输入事项结束 0不是 1是" />
        </el-form-item>
        <el-form-item label="是否审批 0未审批 1审批" prop="approval">
          <el-input v-model="form.approval" placeholder="请输入是否审批 0未审批 1审批" />
        </el-form-item>
        <el-form-item label="是否已经协调 0未协调 1已经协调" prop="coordination">
          <el-input v-model="form.coordination" placeholder="请输入是否已经协调 0未协调 1已经协调" />
        </el-form-item>
        <el-form-item label="是否阅读 0未阅读 1已经阅读" prop="readFlag">
          <el-input v-model="form.readFlag" placeholder="请输入是否阅读 0未阅读 1已经阅读" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { createProjectPlanEvent, updateProjectPlanEvent, deleteProjectPlanEvent, getProjectPlanEvent, getProjectPlanEventPage, exportProjectPlanEventExcel } from "@/api/live/projectPlanEvent";
import Editor from '@/components/Editor';

export default {
  name: "ProjectPlanEvent",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目阶段事项列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        readFlag: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      // 执行查询
      getProjectPlanEventPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        planId: undefined,
        planEventContent: undefined,
        eventDate: undefined,
        milestone: undefined,
        postpone: undefined,
        image: undefined,
        coordinate: undefined,
        leaderId: undefined,
        eventCoordinate: undefined,
        eventFlag: undefined,
        approval: undefined,
        coordination: undefined,
        readFlag: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目阶段事项";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getProjectPlanEvent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目阶段事项";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateProjectPlanEvent(this.form).then(response => {
            this.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createProjectPlanEvent(this.form).then(response => {
          this.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$confirm('是否确认删除项目阶段事项编号为"' + id + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteProjectPlanEvent(id);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      // 执行导出
      this.$confirm('是否确认导出所有项目阶段事项数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportProjectPlanEventExcel(params);
        }).then(response => {
          this.downloadExcel(response, '项目阶段事项.xls');
        })
    }
  }
};
</script>
